<?php
abstract class ExceptionError extends Exception{
	
	/**
	 * 异常代码
	 *
	 * @var string
	 */
	protected $_code = null;
	
	/**
	 * 异常信息
	 *
	 * @var mix [array|string]
	 */
	protected $_message = null;
	
	/**
	 * 错误信息数组
	 *
	 * @var array
	 */
	protected $_errorAry = array();
	
	/**
	 * 初始化$_code与$_message
	 *
	 * @param string $code
	 * @param mix $message [array|string]
	 */
	public function __construct($code = null, $message = null) {
		$this->_code = $code;
		$this->_message = $message;
		if (true === is_array($message)) {
			parent::__construct($message[0], $code);
		} else {
			parent::__construct($message, $code);
		}
	}
	
	/**
	 * 错误控制方法
	 *
	 */
	abstract public function controlError();
	
	/**
	 * 执行跳转
	 *
	 * @throws SystemException
	 * 
	 * @return void
	 */
	protected function _location() {
		if (('9999' == $this->_code) && (null !== $this->_message)) {
			$this->_errorAry[$this->_code][0] = $this->_message[0];
			$this->_errorAry[$this->_code][1] = $this->_message[1];
		}
		
		if (('9999' == $this->_code) && (null === $this->_message)) {
			throw new SystemException('配置文件错误');
		}
		
		Utility::location($this->_errorAry[$this->_code][1] . (strpos('?', $this->_errorAry[$this->_code][1], true) ? '&' : '?') . 'code=' . $this->_code . '&message=' . Utility::argsEncode($this->_errorAry[$this->_code][0]));
	}
	
	
	/**
	 * 返回错误信息
	 *
	 * @throws SystemException
	 * 
	 * @return array
	 */
	protected function _return() {
		if (('9999' == $this->_code) && (null !== $this->_message)) {
			$this->_errorAry[$this->_code] = $this->_message;
		}
		if (('9999' == $this->_code) && (null === $this->_message)) {
			throw new SystemException('配置文件错误');
		}
		return array($this->_code, $this->_errorAry[$this->_code]);
	}
	
}